package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameRank extends JFrame
	{
		//members define
		private var panel70:JPanel;
		private var btn_rank_tab_all:JToggleButton;
		private var btn_rank_tab_boy:JToggleButton;
		private var btn_rank_tab_girl:JToggleButton;
		private var btn_rank_tab_human:JToggleButton;
		private var btn_rank_tab_devil:JToggleButton;
		private var btn_rank_tab_immortal:JToggleButton;
		private var btn_rank_tab_money:JToggleButton;
		private var btn_rank_tab_value_all:JToggleButton;
		private var btn_rank_tab_value_boy:JToggleButton;
		private var btn_rank_tab_value_girl:JToggleButton;
		private var panelItems:JPanel;
		private var panelBCenter:JPanel;
		private var btnPrev:JButton;
		private var labelPage:JLabel;
		private var btnNext:JButton;
		private var labelRankDesc:JLabel;
		private var labelRankSelf:JLabel;
		private var panel25:JPanel;
		private var labelIndex:JLabel;
		private var labelName:JLabel;
		private var labelRace:JLabel;
		private var labelData:JLabel;
		private var labelOperation:JLabel;
		
		private var btn_close:JButton;
		private static var rankVersion:int = 0;
		private static var listCharInfoRank:Array = new Array();
		public function FrameRank()
		{
			super();
			setClosable(false);
			setResizable(false);  
			setBorder(new EmptyBorder());
			btn_close = new JButton();
			btn_close.setSize(new IntDimension(27, 27));
			btn_close.setPreferredSize(new IntDimension(27, 27));
			this.getTitleBar().setCloseButton(btn_close);
			
			//component creation
			setSize(new IntDimension(440, 313));
			setPreferredSize(new IntDimension(440, 313));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			panel25 = new JPanel();
			panel25.setLocation(new IntPoint(90, 9));
			panel25.setSize(new IntDimension(338, 22));
			panel25.setPreferredSize(new IntDimension(338, 22));
			var layout1:EmptyLayout = new EmptyLayout();
			panel25.setLayout(layout1);
			
			labelIndex = new JLabel();
			labelIndex.setLocation(new IntPoint(0, 0));
			labelIndex.setSize(new IntDimension(50, 21));
			labelIndex.setPreferredSize(new IntDimension(50, 21));
			labelIndex.setText("名次");
			
			labelName = new JLabel();
			labelName.setLocation(new IntPoint(51, 0));
			labelName.setSize(new IntDimension(119, 21));
			labelName.setPreferredSize(new IntDimension(119, 21));
			labelName.setText("名字");
			
			labelRace = new JLabel();
			labelRace.setLocation(new IntPoint(171, 0));
			labelRace.setSize(new IntDimension(43, 21));
			labelRace.setPreferredSize(new IntDimension(43, 21));
			labelRace.setText("种族");
			
			labelData = new JLabel();
			labelData.setLocation(new IntPoint(215, 0));
			labelData.setSize(new IntDimension(43, 21));
			labelData.setPreferredSize(new IntDimension(43, 21));
			labelData.setText("等级");
			
			labelOperation = new JLabel();
			labelOperation.setLocation(new IntPoint(259, 0));
			labelOperation.setSize(new IntDimension(79, 21));
			labelOperation.setPreferredSize(new IntDimension(79, 21));
			labelOperation.setText("操作");
			
			panel70 = new JPanel();
			panel70.setLocation(new IntPoint(11, 9));
			panel70.setSize(new IntDimension(76, 235));
			panel70.setPreferredSize(new IntDimension(76, 235));
			var layout2:FlowLayout = new FlowLayout();
			layout2.setAlignment(AsWingConstants.CENTER);
			layout2.setHgap(0);
			layout2.setVgap(0);
			panel70.setLayout(layout2);
			
			btn_rank_tab_all = new JToggleButton();
			btn_rank_tab_all.setLocation(new IntPoint(0, 0));
			btn_rank_tab_all.setSize(new IntDimension(72, 23));
			btn_rank_tab_all.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_all.setText("label");
			
			btn_rank_tab_boy = new JToggleButton();
			btn_rank_tab_boy.setLocation(new IntPoint(0, 21));
			btn_rank_tab_boy.setSize(new IntDimension(59, 23));
			btn_rank_tab_boy.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_boy.setText("label");
			
			btn_rank_tab_girl = new JToggleButton();
			btn_rank_tab_girl.setLocation(new IntPoint(2, 46));
			btn_rank_tab_girl.setSize(new IntDimension(59, 23));
			btn_rank_tab_girl.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_girl.setText("label");
			
			btn_rank_tab_human = new JToggleButton();
			btn_rank_tab_human.setLocation(new IntPoint(2, 69));
			btn_rank_tab_human.setSize(new IntDimension(59, 23));
			btn_rank_tab_human.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_human.setText("label");
			
			btn_rank_tab_devil = new JToggleButton();
			btn_rank_tab_devil.setLocation(new IntPoint(2, 92));
			btn_rank_tab_devil.setSize(new IntDimension(59, 23));
			btn_rank_tab_devil.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_devil.setText("label");
			
			btn_rank_tab_immortal = new JToggleButton();
			btn_rank_tab_immortal.setLocation(new IntPoint(2, 115));
			btn_rank_tab_immortal.setSize(new IntDimension(59, 23));
			btn_rank_tab_immortal.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_immortal.setText("label");
			
			btn_rank_tab_money = new JToggleButton();
			btn_rank_tab_money.setLocation(new IntPoint(2, 138));
			btn_rank_tab_money.setSize(new IntDimension(59, 23));
			btn_rank_tab_money.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_money.setText("label");
			
			btn_rank_tab_value_all = new JToggleButton();
			btn_rank_tab_value_all.setLocation(new IntPoint(2, 161));
			btn_rank_tab_value_all.setSize(new IntDimension(72, 21));
			btn_rank_tab_value_all.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_value_all.setText("label");
			
			btn_rank_tab_value_boy = new JToggleButton();
			btn_rank_tab_value_boy.setLocation(new IntPoint(2, 184));
			btn_rank_tab_value_boy.setSize(new IntDimension(59, 23));
			btn_rank_tab_value_boy.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_value_boy.setText("label");
			
			btn_rank_tab_value_girl = new JToggleButton();
			btn_rank_tab_value_girl.setLocation(new IntPoint(2, 207));
			btn_rank_tab_value_girl.setSize(new IntDimension(72, 23));
			btn_rank_tab_value_girl.setPreferredSize(new IntDimension(72, 23));
			btn_rank_tab_value_girl.setText("label");
			
			panelItems = new JPanel();
			panelItems.setLocation(new IntPoint(90, 35));
			panelItems.setSize(new IntDimension(338, 209));
			panelItems.setPreferredSize(new IntDimension(338, 209));
			var layout3:GridLayout = new GridLayout();
			layout3.setRows(10);
			layout3.setColumns(1);
			layout3.setHgap(0);
			layout3.setVgap(1);
			panelItems.setLayout(layout3);
			
			panelBCenter = new JPanel();
			panelBCenter.setLocation(new IntPoint(207, 244));
			panelBCenter.setSize(new IntDimension(104, 24));
			panelBCenter.setPreferredSize(new IntDimension(104, 24));
			var layout4:FlowLayout = new FlowLayout();
			layout4.setAlignment(AsWingConstants.CENTER);
			layout4.setHgap(5);
			layout4.setVgap(0);
			layout4.setMargin(false);
			panelBCenter.setLayout(layout4);
			
			btnPrev = new JButton();
			btnPrev.setLocation(new IntPoint(6, 0));
			btnPrev.setSize(new IntDimension(29, 24));
			btnPrev.setPreferredSize(new IntDimension(29, 24));
			btnPrev.setText("上一页");
			
			labelPage = new JLabel();
			labelPage.setLocation(new IntPoint(53, 4));
			labelPage.setSize(new IntDimension(36, 16));
			labelPage.setPreferredSize(new IntDimension(36, 16));
			labelPage.setText("10/10");
			
			btnNext = new JButton();
			btnNext.setLocation(new IntPoint(56, 24));
			btnNext.setSize(new IntDimension(29, 24));
			btnNext.setPreferredSize(new IntDimension(29, 24));
			btnNext.setText("下一页");
			
			labelRankDesc = new JLabel();
			labelRankDesc.setLocation(new IntPoint(10, 248));
			labelRankDesc.setSize(new IntDimension(60, 16));
			labelRankDesc.setPreferredSize(new IntDimension(60, 16));
			labelRankDesc.setText("你的名次:");
			
			labelRankSelf = new JLabel();
			labelRankSelf.setLocation(new IntPoint(70, 248));
			labelRankSelf.setSize(new IntDimension(50, 16));
			labelRankSelf.setPreferredSize(new IntDimension(50, 16));
			labelRankSelf.setText("未上榜");
			labelRankSelf.setHorizontalAlignment(AsWingConstants.LEFT);
			
			//component layoution
			getContentPane().append(panel25);
			getContentPane().append(panel70);
			getContentPane().append(panelItems);
			getContentPane().append(panelBCenter);
			getContentPane().append(labelRankDesc);
			getContentPane().append(labelRankSelf);
			
			panel25.append(labelIndex);
			panel25.append(labelName);
			panel25.append(labelRace);
			panel25.append(labelData);
			panel25.append(labelOperation);
			
			panel70.append(btn_rank_tab_all);
			panel70.append(btn_rank_tab_boy);
			panel70.append(btn_rank_tab_girl);
			panel70.append(btn_rank_tab_human);
			panel70.append(btn_rank_tab_devil);
			panel70.append(btn_rank_tab_immortal);
			panel70.append(btn_rank_tab_money);
			panel70.append(btn_rank_tab_value_all);
			panel70.append(btn_rank_tab_value_boy);
			panel70.append(btn_rank_tab_value_girl);
			
			panelBCenter.append(btnPrev);
			panelBCenter.append(labelPage);
			panelBCenter.append(btnNext);
			
			//--------------------------------------
			Client.getInstance().addEventListener("400", phRank_400);
			this.setClipMasked(false);
			getContentPane().setClipMasked(false);
			setImages();
		}
		
		private var _mallItems:Array = new Array();
		public function setImages():void
		{
			var img_background:DisplayObject = Client.getUIElement("img_rank_bg") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_background));
			setSizeWH(img_background.width,img_background.height);
			setSize(new IntDimension(img_background.width, img_background.height));
			setPreferredSize(new IntDimension(img_background.width, img_background.height));
			setLocationXY((Engine.W - img_background.width) / 2,(Engine.H - img_background.height)/2);
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			
			btn_rank_tab_all.setSelected(true);
			
			btn_rank_tab_all.addActionListener(onBtnRankAll);
			btn_rank_tab_boy.addActionListener(onBtnRankBoy);
			btn_rank_tab_girl.addActionListener(onBtnRankGirl);
			btn_rank_tab_human.addActionListener(onBtnRankHuman);
			btn_rank_tab_devil.addActionListener(onBtnRankDevil);
			btn_rank_tab_immortal.addActionListener(onBtnRankImmortal);
			btn_rank_tab_money.addActionListener(onBtnRankMoney);
			btn_rank_tab_value_all.addActionListener(onBtnRankValueAll);
			btn_rank_tab_value_boy.addActionListener(onBtnRankValueBoy);
			btn_rank_tab_value_girl.addActionListener(onBtnRankValueGirl);
			
			
			
			btn_rank_tab_all.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_all.setText("等级榜");
			btn_rank_tab_boy.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_boy.setText("等级榜(男)");
			btn_rank_tab_girl.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_girl.setText("等级榜(女)");
			btn_rank_tab_human.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_human.setText("等级榜(人)");
			btn_rank_tab_devil.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_devil.setText("等级榜(魔)");
			btn_rank_tab_immortal.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_immortal.setText("等级榜(仙)");
			btn_rank_tab_money.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_money.setText("财富榜");
			btn_rank_tab_value_all.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_value_all.setText("身价榜");
			btn_rank_tab_value_boy.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_value_boy.setText("身价榜(男)");
			btn_rank_tab_value_girl.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_rank_tab_value_girl.setText("身价榜(女)");

			btn_rank_tab_all.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_all.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_boy.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_boy.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_girl.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_girl.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_human.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_human.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_devil.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_devil.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_immortal.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_immortal.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_money.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_money.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_value_all.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_value_all.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_value_boy.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_value_boy.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_value_girl.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_rank_tab_value_girl.setVerticalTextPosition(AsWingConstants.CENTER);
			
			var group:ButtonGroup = new ButtonGroup();
			group.appendAll(btn_rank_tab_all,btn_rank_tab_boy,btn_rank_tab_girl,btn_rank_tab_human
				,btn_rank_tab_devil,btn_rank_tab_immortal,btn_rank_tab_money,btn_rank_tab_value_all
				,btn_rank_tab_value_boy,btn_rank_tab_value_girl);
			

			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 12, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			
			btn_rank_tab_all.setFont(font);
			btn_rank_tab_all.setTextFilters(new Array(filter));
			btn_rank_tab_boy.setFont(font);
			btn_rank_tab_boy.setTextFilters(new Array(filter));
			btn_rank_tab_girl.setFont(font);
			btn_rank_tab_girl.setTextFilters(new Array(filter));
			btn_rank_tab_human.setFont(font);
			btn_rank_tab_human.setTextFilters(new Array(filter));
			btn_rank_tab_devil.setFont(font);
			btn_rank_tab_devil.setTextFilters(new Array(filter));
			btn_rank_tab_immortal.setFont(font);
			btn_rank_tab_immortal.setTextFilters(new Array(filter));
			btn_rank_tab_money.setFont(font);
			btn_rank_tab_money.setTextFilters(new Array(filter));
			btn_rank_tab_value_all.setFont(font);
			btn_rank_tab_value_all.setTextFilters(new Array(filter));
			btn_rank_tab_value_boy.setFont(font);
			btn_rank_tab_value_boy.setTextFilters(new Array(filter));
			btn_rank_tab_value_girl.setFont(font);
			btn_rank_tab_value_girl.setTextFilters(new Array(filter));
			
			
			btnPrev.addActionListener(onBtnPrev);
			btnNext.addActionListener(onBtnNext);
			labelPage.setForeground(ASColor.WHITE);
			labelPage.setFont(font);
			labelPage.setTextFilters( new Array(filter));
			
			labelRankDesc.setForeground(ASColor.WHITE);
			labelRankDesc.setFont(font);
			labelRankDesc.setTextFilters( new Array(filter));
			
			labelRankSelf.setForeground(ASColor.ORANGE);
			labelRankSelf.setFont(font);
			labelRankSelf.setTextFilters( new Array(filter));
			

			font = new ASFont("宋体", 14, false, false, false, false);
			
			labelIndex.setForeground(ASColor.ORANGE);
			labelIndex.setFont(font);
			labelIndex.setTextFilters( new Array(filter));
			
			labelName.setForeground(ASColor.ORANGE);
			labelName.setFont(font);
			labelName.setTextFilters( new Array(filter));
			
			labelRace.setForeground(ASColor.ORANGE);
			labelRace.setFont(font);
			labelRace.setTextFilters( new Array(filter));
			
			labelData.setForeground(ASColor.ORANGE);
			labelData.setFont(font);
			labelData.setTextFilters( new Array(filter));
			
			labelOperation.setForeground(ASColor.ORANGE);
			labelOperation.setFont(font);
			labelOperation.setTextFilters( new Array(filter));

			btnPrev.setText("");
			btnNext.setText("");
			
			btnPrev.wrapSimpleButton(Client.getUIElement("btn_prev") as SimpleButton);
			btnNext.wrapSimpleButton(Client.getUIElement("btn_next") as SimpleButton);
			
			for(var i:int = 0; i < _itemsPerPage; i++)
			{
				var item:PaneRankItem = new PaneRankItem;
				panelItems.append(item);
				_mallItems.push(item);
			}
			
			onBtnRankAll(null);
		}
		private function phRank_400(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phRank_400", msg);
			
			var index:int = 0;
			var version:int = msg[index++];
			var type:int = msg[index++];
			var page_index:int = msg[index++];
			var item_per_page:int = msg[index++];
			var count:int = msg[index++];
			if(listCharInfoRank[type] == null)
				listCharInfoRank[type] = new Array;
			if(rankVersion != version)
			{
				listCharInfoRank[type].splice(0,listCharInfoRank[type].length);
				rankVersion = version;
			}

			for(var i:int = 0; i != count; i++)
			{
				var obj:Object = new Object;
				obj.index = msg[index++]+1;
				obj.id = msg[index++];
				obj.m_nRace = msg[index++];
				obj.m_nGender = msg[index++];
				obj.name = msg[index++];
				obj.m_nLevel = msg[index++];
				obj.data = msg[index++];

				listCharInfoRank[type][obj.index-1] = obj;
			}
			updatePage(false);
		}
		private function onBtnRankAll(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 0;
			labelData.setText('等级');
			updatePage();
		}
		private function onBtnRankBoy(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 1;
			labelData.setText('等级');
			updatePage();
		}
		private function onBtnRankGirl(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 2;
			labelData.setText('等级');
			updatePage();
		}
		
		private function onBtnRankHuman(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 3;
			labelData.setText('等级');
			updatePage();
		}
		private function onBtnRankDevil(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 4;
			labelData.setText('等级');
			updatePage();
		}
		private function onBtnRankImmortal(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 5;
			labelData.setText('等级');
			updatePage();
		}
		private function onBtnRankMoney(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 6;
			labelData.setText('铜币');
			updatePage();
		}
		
		private function onBtnRankValueAll(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 7;
			labelData.setText('身价');
			updatePage();
		}
		
		private function onBtnRankValueBoy(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 8;
			labelData.setText('身价');
			updatePage();
		}
		
		private function onBtnRankValueGirl(e:Event):void
		{
			_currentPageIndex = 0;
			_currentPageType = 9;
			labelData.setText('身价');
			updatePage();
		}
		
		private var _currentPageType:int = 0;
		private var _currentPageIndex:int = 0;
		private var _currentPageIndexAll:int = 0;
		private var _itemsPerPage:int = 10;
		public function updatePage(updateFromServer:Boolean = true):void
		{
			if(listCharInfoRank[_currentPageType] == null)
				listCharInfoRank[_currentPageType] = new Array;
			
			var objects:Array = listCharInfoRank[_currentPageType];

			
			var selfRank:int = 0;
			
			for each(var rank:Object in objects)
			{
				if(rank.id == CharInfo.accountId)
					selfRank = rank.index;
			}
			labelRankSelf.setText(selfRank == 0 ? "未上榜":selfRank.toString());
			
			if(updateFromServer)
			{
				var version:int = rankVersion;
				if(objects[_currentPageIndex*10] == null)
					version = 0;
				Client.getInstance().sendPacketLogic(400,[version,_currentPageType,_currentPageIndex,10]);
			}
			
			for each(var obj:Object in _mallItems)
			{
				obj.item = null;
			}
			var nIndex:int = 0;
			var nCount:int = 0;

			nIndex = 0;
			for each(var item:Object in objects)
			{
				nCount++;
				if(nCount <= _currentPageIndex*_itemsPerPage)
					continue;
				_mallItems[nIndex++].item = item;
				if(nIndex >= _itemsPerPage)
					break;
			}
			
			var nCount1:int = 100;
			_currentPageIndexAll = Math.floor((nCount1+_itemsPerPage-1)/_itemsPerPage);
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
			labelPage.pack();
			
		}
		
		private function onBtnPrev(event:Event):void
		{
			_currentPageIndex--;
			if(_currentPageIndex < 0)
				_currentPageIndex = 0;
			else
				updatePage();
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
			labelPage.pack();
		}
		private function onBtnNext(event:Event):void
		{
			_currentPageIndex++;
			if(_currentPageIndex > _currentPageIndexAll-1)
				_currentPageIndex = _currentPageIndexAll-1;
			else
				updatePage();
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
			labelPage.pack();
		}
		
		public static var _frame:FrameRank = null;
		public static function show():void
		{
			if(isShowing())
			{
				hide();
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameRank();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			Client.getInstance().sendPacketLogic(12,[1,0]);
			Client.getInstance().sendPacketLogic(12,[2,0]);
			
			_frame.x = (Engine.W - _frame.width)/2;
			_frame.y = (Engine.H - _frame.height)/2;
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
	
}

import com.*;
import com.Engine.*;
import com.Packet.*;
import com.UI.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

//import mx.containers.Panel;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;
import org.aswing.tree.AbstractLayoutCache;

/**
 * MyPaneRankItem
 */
class PaneRankItem extends JPanel{
	
	//members define
	private var labelIndex:JLabel;
	private var labelName:JLabelButton;
	private var labelRace:JLabel;
	private var labelData:JLabel;
	private var panel31:JPanel;
	private var btn_rank_watch:JButton;
	private var btn_rank_friend:JButton;
	private var btn_rank_compare:JButton;
	
	
	/**
	 * MyPaneRankItem Constructor
	 */
	public function PaneRankItem(){
		//component creation
		setSize(new IntDimension(338, 20));
		setPreferredSize(new IntDimension(338, 20));
		var layout0:EmptyLayout = new EmptyLayout();
		setLayout(layout0);
		
		labelIndex = new JLabel();
		labelIndex.setLocation(new IntPoint(0, 1));
		labelIndex.setSize(new IntDimension(50, 16));
		labelIndex.setPreferredSize(new IntDimension(50, 16));
		labelIndex.setText("label");
		
		labelName = new JLabelButton();
		labelName.setLocation(new IntPoint(50, 1));
		labelName.setSize(new IntDimension(119, 16));
		labelName.setPreferredSize(new IntDimension(119, 16));
		labelName.setText("label");
		
		labelRace = new JLabel();
		labelRace.setLocation(new IntPoint(171, 1));
		labelRace.setSize(new IntDimension(43, 16));
		labelRace.setPreferredSize(new IntDimension(43, 16));
		labelRace.setText("label");
		
		labelData = new JLabel();
		labelData.setLocation(new IntPoint(215, 1));
		labelData.setSize(new IntDimension(43, 16));
		labelData.setPreferredSize(new IntDimension(43, 16));
		labelData.setText("label");
		
		panel31 = new JPanel();
		panel31.setLocation(new IntPoint(259, 1));
		panel31.setSize(new IntDimension(79, 16));
		panel31.setPreferredSize(new IntDimension(79, 16));
		var layout1:FlowWrapLayout = new FlowWrapLayout();
		layout1.setPreferWidth(200);
		layout1.setAlignment(AsWingConstants.CENTER);
		layout1.setHgap(5);
		layout1.setVgap(0);
		layout1.setMargin(false);
		panel31.setLayout(layout1);
		
		btn_rank_watch = new JButton();
		btn_rank_watch.setLocation(new IntPoint(0, 4));
		btn_rank_watch.setSize(new IntDimension(17, 15));
		btn_rank_watch.setPreferredSize(new IntDimension(17, 15));
		btn_rank_watch.setToolTipText("查看资料");
		btn_rank_watch.setText("label");
		
		btn_rank_friend = new JButton();
		btn_rank_friend.setLocation(new IntPoint(24, 4));
		btn_rank_friend.setSize(new IntDimension(17, 15));
		btn_rank_friend.setPreferredSize(new IntDimension(17, 15));
		btn_rank_friend.setToolTipText("添加好友");
		btn_rank_friend.setText("label");
		
		btn_rank_compare = new JButton();
		btn_rank_compare.setLocation(new IntPoint(48, 0));
		btn_rank_compare.setSize(new IntDimension(17, 15));
		btn_rank_compare.setPreferredSize(new IntDimension(17, 15));
		btn_rank_compare.setToolTipText("挑战");
		btn_rank_compare.setText("label");
		
		//component layoution
		append(labelIndex);
		append(labelName);
		append(labelRace);
		append(labelData);
		append(panel31);
		
		panel31.append(btn_rank_watch);
		panel31.append(btn_rank_friend);
		panel31.append(btn_rank_compare);
		
		//----------------------------------------
		btn_rank_watch.wrapSimpleButton(Client.getUIElement("btn_rank_watch") as SimpleButton);
		btn_rank_watch.setText('');
		
		btn_rank_friend.wrapSimpleButton(Client.getUIElement("btn_rank_friend") as SimpleButton);
		btn_rank_friend.setText('');
		
		btn_rank_compare.wrapSimpleButton(Client.getUIElement("btn_rank_compare") as SimpleButton);
		btn_rank_compare.setText('');
		
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 12, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 10);

		labelIndex.setForeground(ASColor.ORANGE);
		labelIndex.setFont(font);
		labelIndex.setTextFilters( new Array(filter));
		
		labelRace.setForeground(ASColor.WHITE);
		labelRace.setFont(font);
		labelRace.setTextFilters( new Array(filter));
		
		labelName.setForeground(ASColor.WHITE);
		labelName.setFont(new ASFont("宋体", 12, false, false, true, false));
		labelName.setTextFilters( new Array(filter));
		
		labelData.setForeground(ASColor.WHITE);
		labelData.setFont(font);
		labelData.setTextFilters( new Array(filter));
		

		labelName.addActionListener(onBtnName);
		btn_rank_watch.addActionListener(onBtnWatch);
		btn_rank_friend.addActionListener(onBtnFriend);
		btn_rank_compare.addActionListener(onBtnCompare);
	}
	private function onBtnName(e:Event):void
	{
		if(_item == null)
			return;
		var obj:Object = new Object;
		obj.m_nCharId = int(_item.id);
		obj.m_szCharName = _item.name;
		obj.m_nLevel = int(_item.m_nLevel);
		obj.m_nRace = int(_item.m_nRace);
		obj.m_nGender = int(_item.m_nGender);
		
		var point:IntPoint = AsWingUtils.getStageMousePosition();
		FrameClickChar._objDest = obj;
		FrameClickChar._destCharId = int(obj.m_nCharId);
		FrameClickChar.show(FrameRank._frame,point.x-FrameRank._frame.x,point.y-FrameRank._frame.y);
	}
	
	private function onBtnFriend(e:Event):void
	{
		Client.getInstance().sendPacketLogic(601,[int(_item.id)]);
	}
	private function onBtnWatch(e:Event):void
	{
		Client.getInstance().sendPacketLogic(605,[int(_item.id)]);
	}
	private function onBtnCompare(e:Event):void
	{
		Client.getInstance().sendPacketLogic(300,[int(SceneBattle.BATTLE_TYPE_PVP_COMPARE),int(_item.id)]);
	}
	
	private var _item:Object = null;
	public function set item(val:Object):void
	{
		_item = val;
		labelIndex.setText("");
		labelRace.setText("");
		labelName.setText("");
		labelData.setText("");
		
		btn_rank_watch.setVisible(false);
		btn_rank_friend.setVisible(false);
		btn_rank_compare.setVisible(false);
		
		if(_item == null)
			return;

		labelIndex.setText(_item.index);
		labelRace.setText(_item.m_nRace == 0?"人":(_item.m_nRace == 1?"魔":"仙"));
		labelName.setText(_item.name);
		labelData.setText(_item.data);
		btn_rank_watch.setVisible(true);
		btn_rank_friend.setVisible(true);
		btn_rank_compare.setVisible(true);
		if(_item.m_nGender == 0)
			labelName.setForeground(new ASColor(Engine.colorBoy));
		if(_item.m_nGender == 1)
			labelName.setForeground(new ASColor(Engine.colorGirl));		
	}
	public function get item():Object
	{
		return _item;
	}
	public function clear():void
	{
		setBackgroundDecorator(null);
		item = null;
	}
	//_________getters_________
	
	
	
	
	
	
}